#!/bin/sh
# gfilt: Unix shell script driver for gcc / STL Error Decryptor
#
# usage: gfilt [mixture of compiler and Decryptor options]
#
# Purpose: Distinguish compiler options/args from Decryptor options,
#          make sure all recognized Decryptor options are passed on
#          the Decryptor script command line, and all other options/
#          args are passed on the compiler command line.
#          Filter all compiler output, and send results to stdout.
#
#          (Note: stdout and stderr output streams from the compiler
#          are combined by this process, so the two can no longer be
#          individually redirected afterwards. If this is an issue
#          for anyone, please let me know.
#
# Exit status: The status code returned by the compiler
#
# Contents of the environment variable GFILTOPTS are passed as
# options to the STLFILT script (see the setting of DOPTS below.)
#
# 02/21/03 - Exit status is now status of compilation
# 12/17/04 - Added recognition of several script options that
#            were missing from the case: with, meta, nullarg
#            Added more comments.
#
# Leor Zolman
# BD Software
# www.bdsoft.com
# leor@bdsoft.com
#
#########################################################################
# Configuration section:

COMPILER=c++                            # Your g++ compiler command
STLFILT=/net/cpp-group/Leo/bin/gSTLFilt.pl               # Where you've placed the Perl script
                                        # default options to Decryptor script:
DOPTS="/hdr:m /cand:s /iter:L ${GFILTOPTS:-}"
PAGER=   #more                              # pager of choice, or leave blank for no paging
COPTS=                                  # compiler options

if $COMPILER --version | grep " 3\." >/dev/null      # if gcc 3.x...
then
    COPTS=-fmessage-length=0            # ...this option is needed.
fi

[ $# -eq 0 ] && echo "usage: $0 [options] source-file(s)" && exit 0


# End of configuration section
#########################################################################

GCC_ARGS=
DECRYPTOR_ARGS=


for arg
do
    case $arg in
	[-/]iter:*|[-/]cand:*|[/-]hdr:*|[-/]with:*|[-/]path:*|[/-]showback:*|[/-]width:*|[-/]lognative|[-/]banner:*|[/-]|[-/]nullarg:*|[-/]break:*|[-/]cbreak:*|[-/]closewrap:*|[-/]meta|[-/]meta:*)
            DECRYPTOR_ARGS="$DECRYPTOR_ARGS $arg";;
        *)
            GCC_ARGS="$GCC_ARGS $arg";;
    esac
done


#
# Note that there are several options the Perl script accepts.
# see the comments at the top of gSTLFilt.pl for details.
#

TMPFILE=/tmp/gfilt$$.tmp
touch $TMPFILE
trap "rm $TMPFILE; exit 1" 1 2 3 15

$COMPILER $COPTS $GCC_ARGS >$TMPFILE 2>&1
STATUS=$?

if [ "$PAGER" != "" ]; then
    perl $STLFILT $DOPTS $DECRYPTOR_ARGS < $TMPFILE | $PAGER
else
    perl $STLFILT $DOPTS $DECRYPTOR_ARGS < $TMPFILE
fi

rm $TMPFILE
exit $STATUS
